/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.farmcode.core.runtime.event;

import com.farmcode.api.runtime.BaseEvent;
import com.farmcode.api.runtime.FARMCodeContext;
import com.farmcode.api.runtime.Response;
import com.farmcode.api.runtime.database.DatabaseExplorerAPI;
import com.farmcode.api.runtime.metadata.ObjectInfo;
import com.farmcode.api.util.FARMCodeAPI;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author oiprado
 */
public class ColumnEvent extends BaseEvent<ObjectInfo> {

  @Override
  public Response<ObjectInfo> excecute(FARMCodeContext context) {

//    DatabaseExplorerAPI databaseEngineAPI = null;
    ObjectInfo objectInfo = null;
    try {
//      databaseEngineAPI = FarmcodeAPI.getInstance(DatabaseExplorerAPI.COMPONENT_NAME);
      ObjectInfo type = (ObjectInfo) context.get(FARMCodeContext.CLASS_TYPE);
      objectInfo = databaseExplorerAPI.getColumn(new FARMCodeContext(context), type);
      response.setResult(objectInfo);
    } catch (Exception ex) {
      Logger.getLogger(ColumnEvent.class.getName()).log(Level.SEVERE, null, ex);
      response.addMessage(ex);
    } 
    return response;

  }
}
